package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShopingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "购物车")
@RestController
@RequestMapping("/user/shoppingCart/")
public class ShopingCartUserController {

    @Autowired
    private ShopingCartService shopingCartService;

    /**
     * 添加购物车
     *
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("add")
    @ApiOperation("C端-添加购物车")
    public Result addShopingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shopingCartService.addShopingCart(shoppingCartDTO);
        return Result.success();
    }

    /**
     * C端-获取购物车
     *
     * @return
     */
    @GetMapping("list")
    @ApiOperation("C端-获取购物车")
    public Result<List<ShoppingCart>> list() {
        List<ShoppingCart> list = shopingCartService.list();
        return Result.success(list);
    }

    /**
     * C端-清空购物车
     *
     * @return
     */
    @DeleteMapping("clean")
    @ApiOperation("C端-清空购物车")
    public Result clean() {
        shopingCartService.clean();
        return Result.success();
    }

    /**
     * 删除购物车中一个商品
     *
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("sub")
    @ApiOperation("删除购物车中一个商品")
    public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shopingCartService.subShoppingCart(shoppingCartDTO);
        return Result.success();
    }
}
